var express = require("express");
var router = express.Router();

// 导入用户路由处理函数
const {
  login,
  regUser,
  updatePwd,
  getAvatar,
  uploadPic,
  getUsers,
  getSingle,
  updateInfo,
  deleteUser,
} = require("../handleRouter/users");
// 导入验证登录数据的中间件
const expressJoi = require("@escook/express-joi");
// 导入验证规则的对象
const { reg_login_schema, reg_updatePwd_schema } = require("../schema/users");
// 导入multer包
const multer = require("multer");
// 文件存储位置
const upload = multer({ dest: "public/images/uploads/" });

/**
 * 登录路由
 * POST /login
 */
router.post("/login", expressJoi(reg_login_schema), login);
/**
 * 注册路由
 * POST /regUser
 */
router.post("/regUser", regUser);
/**
 * put/修改密码
 */
router.put("/updatePwd/:id", expressJoi(reg_updatePwd_schema), updatePwd);
/**
 * 获取头像
 */
router.get("/avatar/:id", getAvatar);
/**
 * 修改头像
 */
router.put("/uploadPic/:id", upload.single("avatar"), uploadPic);
/**
 * 获取所有用户信息
 */
router.get("/getUsers", getUsers);
/**
 * 获取单个用户信息
 */
router.get("/getSingle/:id", getSingle);
/**
 * 修改用户信息
 */
router.put("/update", updateInfo);
/**
 * 删除用户
 */
router.delete("/deleted", deleteUser);

// 导出路由对象
module.exports = router;
